/*
 * Copyright (c) 2009 John Pritchard, WTKX Project Group
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package wtkx;

import wtkx.ui.Objects;

import jbxml.Resolver;

/**
 * This name is not able to be employed as an element name in WTKX XML
 * because this class is abstract.  Use the name "wtkx" for the
 * document root element.
 * 
 * @see Wtkx
 * @author jdp
 */
public abstract class Window
    extends Container
{

    protected Resolver resolver;

    protected final Objects objects = new Objects();


    public Window(){
        super();
    }


    public final Resolver getResolver(){
        return this.resolver;
    }
    public final void setResolver(Resolver r){
        if (null != r){
            if (null == this.resolver)
                this.resolver = r;
            else
                throw new IllegalStateException();
        }
        else
            throw new IllegalArgumentException();
    }
    public final java.lang.Object getObjectById(String id){
        if (null != this.resolver)
            return this.resolver.getObjectById(id);
        else
            throw new IllegalStateException("Missing resolver.");
    }
    public final void setObjectById(String id, java.lang.Object value){
        if (null != id && null != value){
            if (null != this.resolver)
                this.resolver.setObjectById(id,value);
            else
                throw new IllegalStateException("Missing resolver.");
        }
        else
            throw new IllegalArgumentException();
    }
    public final java.lang.Object removeObjectById(String id){
        if (null != this.resolver)
            return this.resolver.removeObjectById(id);
        else
            throw new IllegalStateException("Missing resolver.");
    }
    public Objects getObjects(){
        return this.objects;
    }
    /**
     * Must be called from the application startup.
     */
    public final void init(Application a)
        throws wtkx.be.Function.MethodNotFound
    {
        super.init(a);
        this.objects.init(this,a);
        /*
         * [TODO:Review] This is it for the moment.. 
         */
        this.getResourceCache().loadImages(this,wtkx.in.Script.Icons);
    }
    public void destroy(){
        Resolver resolver = this.resolver;
        if (null != resolver){
            this.resolver = null;
            resolver.destroy();

            this.objects.destroy();
        }
        super.destroy();
    }
    public final Window getWindow() {
        return this;
    }
    public void layout(){
        super.layout();
    }
}
